package com.ourteam.product.api;

import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.ui.dao.ProductUIListDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUIListBean;

public class ProductUIListSearchModel extends AbstractSearchModel<ProductUIListDAOQueryBean> {
	
	private Long id;

	private Long domainId;

	private String type;

	private String code;

	public Long getDomainId() {
		return domainId;
	}

	public void setDomainId(Long domainId) {
		this.domainId = domainId;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductUIListBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(ProductUIListDAOQueryBean queryBean) throws Exception {

		ProductUIListDAOQueryBean.Criteria criteria = queryBean.createCriteria();
		
		if (id != null && id != 0) {
			criteria.andIdEqualTo(id);
		}

		if (domainId != null && domainId != 0) {
			criteria.andDomainIdEqualTo(domainId);
		}

		if (StringUtils.isNotBlank(type)) {
			if ("static".equals(type)) {
				criteria.andTypeEqualTo(type);
			} else {
				criteria.andTypeNotEqualTo("static");
			}
		}

		if (StringUtils.isNotBlank(code)) {
			criteria.andCodeLike(code);
		}

	}

}
